package com.CRApp.controller;

import com.CRApp.pojo.Chat;
import com.CRApp.pojo.Result;
import com.CRApp.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author : chp
 */
@RestController
@RequestMapping("/chat")
@Validated
public class ChatController {
    @Autowired
    private ChatService chatService;
    //上传聊天记录
    @PostMapping("/uploadInput")
    public Result sendChat(@RequestBody Map<String, String> sendMessageData){
        Chat chat = new Chat();
        chat.setUserId(sendMessageData.get("userId"));
        chat.setQuestion(sendMessageData.get("question"));
        chat.setAnswer(sendMessageData.get("answer"));
        chatService.insertChat(chat);
        return Result.success("成功");
    }
    //获取聊天记录
    @PostMapping("/getChat")
    public Result getChat(@RequestBody Map<String, String> getData) {
        String userId = getData.get("userId");
        return Result.success(chatService.getChatList(userId));
    }
}
